Setup Entity Framework Core for MySQL in ASP.NET Core 2
1 min readMar 3, 2018
Microsoft doesn’t have official package to support MySQL data provider for EF Core (yet). There is an open source package corePomelo.EntityFrameworkCore.MySql
maintained by Pomelo Foundation.
We can install this package in .NET Core application using NuGet package manager.
Once package installed, setup connection string in appsettings.json
file:
- Create DbContext and Model classes mapping database tables.
- Configure MySql service in
ConfigureServices
ofStartup.cs
specifying DbContext and connection string. This service shall be queried later for resolving DbContext object via Dependency Injection.
- Accessing DbContext in controller classes
and that should be it!
Your ASP.NET Core 2 application is setup with EF Core and MySQL database.